package com.cgw.auth.controller;

import com.cgw.auth.service.AccountService;
import lombok.RequiredArgsConstructor;
import org.gavin.core.annotation.LogRecord;
import org.gavin.core.annotation.Safety;
import org.gavin.core.domain.R;
import com.cgw.auth.entity.Account;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TestController
 *
 * @author grl
 * @date 2024/1/9
 */
@RestController
@RequiredArgsConstructor
public class TestController {

    private final AccountService accountService;

    @LogRecord(description = "查询所有")
    @GetMapping(value = "/query/list")
    public R<List<Account>> getAccount(){
        List<Account> list = accountService.getAllList();
        return R.ok(list);
    }

    @PostMapping(value = "/add")
    public R<Account> add(@RequestBody Account account){
       accountService.add(account);
        return R.ok(account);
    }

    @Safety
    @LogRecord(description = "查询详情")
    @GetMapping(value = "/details")
    public R<Account> getDetails(@RequestParam(value = "detailsId") Integer detailsId){
        Account details = accountService.getDetails(detailsId);
        return R.ok(details);
    }

    @Safety
    @LogRecord(description = "查询详情")
    @PostMapping(value = "/body/details")
    public R<Account> getBodyDetails(@RequestParam(value = "detailsId") Integer detailsId){
        Account details = accountService.getDetails(detailsId);
        return R.ok(details);
    }

    @Safety
    @LogRecord(description = "查询详情")
    @PostMapping(value = "/obj/details")
    public R<Account> getObjDetails(@RequestBody Account account){
        Account details = accountService.getDetails(account.getId());
        return R.ok(details);
    }

    public static void main(String[] args) {
        String join = String.join("", "spring.shardingsphere.datasource.", "45,89");
        System.out.println(join);
    }
}
